The fundamental principle for calculating the transfer duration is the relationship between file size, speed, and time. The simulation uses the following formula:
Time (seconds) = Total File Size (MB) / Speed (MB/s)
For example, to transfer a 1024 MB (1 GB) file with a drive that writes at 100 MB/s, the calculation would be: 1024 / 100 = 10.24 seconds.
It's important to distinguish between Megabytes per second (MB/s) and Megabits per second (Mbps). Internet speeds are often advertised in Mbps, while file sizes are measured in MB.
The key difference is: 1 Byte = 8 bits. Therefore, 1 MB/s = 8 Mbps. This simulation uses MB/s for all speed ratings to align directly with file sizes in Megabytes (MB) and Gigabytes (GB).
Each USB standard has a defined theoretical maximum speed. This simulation uses realistic average speeds for read and write operations, which are listed below:
| USB Type | Write Speed (MB/s) | Read Speed (MB/s) |
|---|---|---|
| USB 2.0 | 25 | 35 |
| USB 3.0 | 100 | 150 |
| USB 3.2 | 300 | 400 |
| USB 4.0 | 800 | 1000 |
In the real world, transfer speeds are never perfectly constant. They fluctuate due to various factors like system load, file types, and hardware condition. To simulate this, a small random variance is applied to the displayed speed during a transfer.
The code achieves this with: (Math.random() - 0.5) * 0.1. This creates a random fluctuation of up to +/- 5% from the base speed, making the live "MB/s" display more dynamic and realistic.